{ Siberian Olympiad. 1 stage.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/wso/stage1/wso_1stage.pdf
  Problem 4
  Points: 95
}
{$APPTYPE CONSOLE}
const inf=100000;
var i,n,m,j,code,xb,xa,yb,ya,cur:integer; x,y:array[1..2001] of longint; result:int64;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(n,m);
result:=0;
if n=0 then result:=0 else begin
for I := 1 to n+m do begin
  cur:=4;
  readln(x[i],y[i]);
  j:=i;
  code:=0;
  xb:=0;
  xa:=0;
  ya:=0;
  yb:=0;
  while (j>1) and (code<>4) do begin
    dec(j);
  if (x[j]<>inf) and (y[j]<>inf) then begin
    if (x[i]=x[j]) and (y[i]<y[j]) and (ya=0) then begin
      inc(code);
      inc(ya);
      dec(cur,2);
    end else
        if (x[i]=x[j]) and (y[i]>y[j]) and (yb=0) then begin
      inc(code);
      inc(yb);
      dec(cur,2);
    end else
    if (x[i]>x[j]) and (y[i]=y[j]) and (xb=0) then begin
      inc(code);
      inc(xb);
      dec(cur,2);
    end else
    if (x[i]<x[j]) and (y[i]=y[j]) and (xa=0) then begin
      inc(code);
      inc(xa);
      dec(cur,2);
    end;
  end;
  end;
  if xb+xa=2 then inc(cur,(2-yb-ya));
  if yb+ya=2 then inc(cur,(2-xb-xa));
  if cur<0 then cur:=0;
  inc(result,cur);
  if ((code=0) and (i>n)) or (code=4) or (cur=0) then begin
    if (code<>4) and (cur<>0) then dec(result,4);
    x[i]:=inf;
    y[i]:=inf;
  end;
end;
end;
writeln(result);
close(input);
close(output);
end.